package com._51cto.healthy.controller;

import com._51cto.healthy.content.P;
import com._51cto.healthy.content.R;
import com._51cto.healthy.pojo.Examination;
import com._51cto.healthy.service.ExaminationService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/examination")
public class ExaminationController {

    @DubboReference
    private ExaminationService examinationService;

    @GetMapping("/page/{pageSize}/{pageNum}")
    public R queryAll(@RequestParam(value = "query", required = false/*表示参数不是必填项*/) String query,
                      @PathVariable("pageNum") Integer pageNum,
                      @PathVariable("pageSize") Integer pageSize) {
        P<Examination> examinationP = null;
        boolean b = false;
        while(!b){
            try {
                examinationP = examinationService.queryPageList(query,pageNum,pageSize);
                b = true;
            }catch (RuntimeException e){
                b = false;
            }
        }
        return R.success(examinationP);
    }

    @DeleteMapping("/{id}")
    public R delete(@PathVariable Integer id){
        boolean a = false;
        while(!a){
            try{
                examinationService.deleteByPK(id);
                a = true;
            }catch (RuntimeException e){
                a = false;
            }
        }
        return R.success("删除成功");
    }
}
